<template>
  <div class="thesis-detail">
      <PageTemplate>
        <div class="pur" slot="content">
            <div class="container container-top">
                <el-form  label-width="150px"  :model="paper" :rules="paperRules"  ref="paper">
                    <el-collapse v-model="showCollapse2" accordion>
                        <el-collapse-item name="1" class="search-collapse-title">
                            <template slot="title">
                                <span class="vertical-bar" style="margin:0;" ></span>
                                <font  class="collapse-content" >{{$t('cm.baseinfo')}}</font>
                            </template>
                            <div class="div-form">
                                <el-row>
                                    <!--主题-->
                                    <el-col :span="12">
                                        <el-form-item  :label="$t('pur.process_folio')"  prop="folio" >
                                            <el-input   size="small" class="form-input" v-model="paper.folio" :disabled="true" placeholder="提交后自动生成"></el-input>
                                        </el-form-item>
                                    </el-col>
                                    <!--流程名称-->
                                    <el-col :span="12">
                                        <el-form-item :label="$t('pur.process_procChName')">
                                            <el-input   size="small" class="form-input" v-model="flow_access.procChName" :disabled="true"></el-input>
                                        </el-form-item>
                                    </el-col>
                                </el-row>
                            </div>
                        </el-collapse-item>
                    </el-collapse>
                    <el-collapse v-model="showCollapse" accordion>
                        <el-collapse-item name="1" class="search-collapse-title">
                            <template slot="title">
                                <span class="vertical-bar" style="margin:0;" ></span>
                                <font  class="collapse-content" >{{$t('te.add')}}( <font >*</font> {{$t('te.must_fill')}})</font>
                            </template>

                            <div class="div-form">
                              <el-row v-if="type === 'add' || type === 'edit'">
                                <el-col :span="12">
                                  <el-form-item label="操作类型" prop="operateType">
                                    <span>{{type === 'add' ? '论文新增' : '论文信息变更'}}</span>
                                  </el-form-item>
                                </el-col>
                              </el-row>
                              <el-row>
                                <el-col :span="12">
                                  <el-form-item label="论文名称" prop="paperName">
                                    <span v-if="!edit">{{paper.paperName}}</span>
                                    <el-input class="form-input" v-else v-model="paper.paperName" placeholder="50个字以内" size="small"></el-input>
                                  </el-form-item>
                                </el-col>
                                <el-col :span="12" v-if="type === 'add'">
                                  <el-form-item label="关键词" prop="keyword">
                                    <span v-if="!edit">{{paper.keyword}}</span>
                                    <el-input class="form-input" v-else v-model="paper.keyword" size="small"></el-input>
                                  </el-form-item>
                                </el-col>
                                <el-col :span="12" v-if="type === 'edit'">
                                  <el-form-item label="论文英文名称" prop="paperEnName">
                                    <span v-if="!edit">{{paper.paperEnName}}</span>
                                    <el-input class="form-input" v-else v-model="paper.paperEnName" placeholder="50个字以内" size="small"></el-input>
                                  </el-form-item>
                                </el-col>
                              </el-row>
                              <el-row>
                                <el-col :span="24">
                                  <el-form-item label="摘要" prop="summary">
                                    <span v-if="!edit">{{paper.summary}}</span>
                                    <el-input v-else class="form-input" v-model="paper.summary" type="textarea" placeholder="500个字以内" size="small"></el-input>
                                  </el-form-item>
                                </el-col>
                              </el-row>
                              <el-row>
                                <el-col :span='12' v-if="type === 'add'">
                                    <el-form-item label="专业领域" prop="professional">
                                        <span v-if="!edit">{{paper.professional}}</span>
                                        <el-select
                                          v-else
                                          class="form-input"
                                          v-model="paper.professional"
                                          placeholder="请选择"
                                          size="small">
                                          <el-option
                                            v-for="item in professionalMap"
                                            :key="item.dictText"
                                            :label="item.dictText"
                                            :value="item.dictKey+''">
                                          </el-option>
                                        </el-select>
                                    </el-form-item>
                                </el-col>
                                <el-col :span="12" v-if="type === 'edit'">
                                  <el-form-item label="关键词" prop="keyword">
                                    <span v-if="!edit">{{paper.keyword}}</span>
                                    <el-input class="form-input" v-else v-model="paper.keyword" size="small"></el-input>
                                  </el-form-item>
                                </el-col>
                                <el-col :span="12">
                                  <el-form-item label="第一作者" prop="firstAuthor">
                                    <span v-if="!edit">{{paper.firstAuthor}}</span>
                                    <el-input v-else class="form-input" v-model="paper.firstAuthor" size="small"></el-input>
                                  </el-form-item>
                                </el-col>
                                <el-col :span="12">
                                  <el-form-item label="其它作者" prop="otherAuthor">
                                    <span v-if="!edit">{{paper.otherAuthor}}</span>
                                    <el-input v-else class="form-input" v-model="paper.otherAuthor" size="small"></el-input>
                                  </el-form-item>
                                </el-col>
                              </el-row>
                              <el-row>
                                  <el-col :span='12'>
                                    <el-form-item label="是否刊出" prop="isPublish">
                                      <span v-if="!edit">{{paper.isPublish == 1 ? '是' : '否'}}</span>
                                      <el-radio-group v-else v-model="paper.isPublish" size="small">
                                        <el-radio label="1">是</el-radio>
                                        <el-radio label="0">否</el-radio>
                                      </el-radio-group>
                                    </el-form-item>
                                  </el-col>
                              </el-row>
                              <el-row>
                                  <el-col :span="12">
                                    <el-form-item v-if="paper.isPublish == 1" label="期刊名称" prop="periodicalName">
                                      <span v-if="!edit">{{paper.periodicalName}}</span>
                                      <el-input class="form-input" v-else v-model="paper.periodicalName" size="small"></el-input>
                                    </el-form-item>
                                  </el-col>
                                  <el-col :span="12">
                                    <el-form-item v-if="paper.isPublish == 1" label="是否核心期刊" prop="periodicalCore">
                                      <span v-if="!edit">{{paper.periodicalCore}}</span>
                                      <el-select class="form-input"  v-else v-model="paper.periodicalCore"  placeholder="请选择" size="small">
                                          <el-option label="是" value="1"></el-option>
                                          <el-option label="否" value="0"></el-option>
                                        </el-select>
                                    </el-form-item>
                                  </el-col>
                              </el-row>
                              <el-row>
                                <el-col :span='12' v-if="paper.isPublish == 1">
                                    <el-form-item label="发表日期" prop="publishDate">
                                      <span v-if="!edit">{{paper.publishDate | dateFormat}}</span>
                                      <el-date-picker
                                        v-else
                                        class="form-input"
                                        v-model="paper.publishDate"
                                        value-format="yyyy-MM-dd HH:mm:ss"
                                        type="date"
                                        placeholder="选择日期"

                                        size="small">
                                      </el-date-picker>
                                    </el-form-item>
                                </el-col>
                                <el-col :span="12" v-if="paper.isPublish == 1">
                                    <el-form-item label="索引类别" prop="indexType">
                                      <span v-if="!edit">{{paper.indexType}}</span>
                                      <el-select
                                        v-else
                                        class="form-input"
                                        v-model="paper.indexType"
                                        placeholder="请选择"
                                        size="small">
                                        <el-option
                                          v-for="item in indexTypeMap"
                                          :key="item.dictText"
                                          :label="item.dictText"
                                          :value="item.dictKey+''">
                                        </el-option>
                                      </el-select>
                                    </el-form-item>
                                  </el-col>
                              </el-row>
                              <el-row v-if="type == 'edit'">
                                <el-col :span="12">
                                    <el-form-item label="专业分部" prop="deptId">
                                      <span v-if="!edit">{{paper.deptId}}</span>
                                      <el-select
                                        v-else
                                        class="form-input"
                                        v-model="paper.deptId"
                                        placeholder="请选择"
                                        size="small">
                                        <el-option
                                          v-for="item in deptIdMap"
                                          :key="item.dictText"
                                          :label="item.dictText"
                                          :value="item.dictKey+''">
                                        </el-option>
                                      </el-select>
                                    </el-form-item>
                                  </el-col>
                              </el-row>
                              <el-row>
                                <el-col :span="10">
                                  <el-form-item label="论文附件" prop="fileId">

                                    <FileUploadCommon

                                      @uploadSuccess="uploadSuccess"
                                      @uploadRemove="uploadRemove"
                                      :fileList="paperFileList"
                                      :limit="1">
                                      </FileUploadCommon>
                                  </el-form-item>
                                </el-col>
                              </el-row>
                            </div>

                        </el-collapse-item>
                    </el-collapse>
                    <!--流程部分-->
                    <el-collapse v-model="showCollapse1" accordion v-if="type !='look'&&type !='done'">
                        <el-collapse-item name="1" class="search-collapse-title">
                            <template slot="title">
                                <span class="vertical-bar" style="margin:0;" ></span>
                                <font  class="collapse-content" >{{$t('fe.procDeal')}}</font>
                            </template>
                            <div>
                                <procApprove
                                  :isStartAct="isStartAct"
                                  :procObj="flowDetails"
                                  :flow_access="flow_access" >
                                </procApprove>
                            </div>
                        </el-collapse-item>
                    </el-collapse>
                    <!--流程部分 我的已办-->
                    <el-collapse v-model="showCollapse1" accordion v-if="type =='done'">
                        <el-collapse-item name="1" class="search-collapse-title">
                            <template slot="title">
                                <span class="vertical-bar" style="margin:0;" ></span>
                                <font  class="collapse-content" >{{$t('fe.procDeal')}}</font>
                            </template>
                            <div>
                              <!--当前处理环节-->
                              <el-row class="flow-detail-row">
                                <el-col :span="4" class="flow-detail-col1" >{{$t('ndt.now_deal_actor')}} <span>&nbsp;</span></el-col>
                                <el-col :span="6" class="flow-detail-col2">{{flow_access.act_name}}</el-col>
                              </el-row>
                              <!--处理结论-->
                              <!--下一步处理环节-->
                              <el-row class="flow-detail-row">
                                <el-col :span="4" class="flow-detail-col1" >处理人</el-col>
                                <el-col :span="6" class="flow-detail-col2">
                                  {{flow_access.approveMan}}
                                </el-col>
                              </el-row>
                              <!--下一步处理人-->
                              <!--抄送-->
                              <!--处理结论-->
                            </div>
                        </el-collapse-item>
                    </el-collapse>
                </el-form>
            </div>
            <el-row class="row-empty-30"></el-row>
            <!-- 固定按钮的位置 -->
            <!--使用组件的方式来进行-->
            <fixedbutton v-if="type !='look'&& type != 'done'">
                <div slot="fixbtn">
                    <el-button class="btn-default" type="primary" size="small" @click="saveProcHandle" >{{$t('cm.commit')}}</el-button>
                    <el-button v-if="type == 'add' || type == 'draftEdit'" class="btn-default" type="primary" size="small" @click="saveDraftHandle">{{$t('cm.savedraft')}}</el-button>
                </div>
            </fixedbutton>
            <PurProcessDemWithinFileList
              ref="PurProcessDemWithinFileList"
              :fileListDislogVisible="fileListDislogVisible"
              @addFileList="addFileList"
              @closeFileListDislog="closeFileListDislog"
            >
            </PurProcessDemWithinFileList>
        </div>
      </PageTemplate>
  </div>
</template>

<script>
import PageTemplate from '@/components/common/PageTemplate'
import {
  getStartAct,
  insertwin,
  delFile,
  addDraft,
  getNextApprovePerson,
  getBpmPscActInfo,
  getWFConfigActivity,
  getWFConfigProcID,
  getCurrentUserDetail,
  getCurrentUserBoss
} from '@/api/api.js'
import PersonSelect from '@/components/asc/PersonSelect'
import procApprove from '@/components/common/procApprove'
import fixedbutton from '@/components/common/fixedbutton'
import download from '@/components/common/download'
import PurProcessDemWithinFileList from '@/components/purchase/PurProcessDemWithinFileList'
import { mapState, mapActions } from 'vuex'
import * as Constant from '@/utils/constant'
import { ALERT } from '@/utils/responseHandle'
import api_pur from '@/api/api_pur'
import store from '@/store'
import sys_manage from '@/api/sys_manage'
import api_sri from '@/api/api_sri'
import FileUploadCommon from '@/components/common/FileUploadCommon'
import { COMMON } from '@/utils/commonUtil'

export default {
    components:{
      PageTemplate,
      PersonSelect,
      procApprove,
      fixedbutton,
      download,
      PurProcessDemWithinFileList,
      FileUploadCommon
    },
    props: {
      // look：查看；edit：编辑; add: 新增; approve:审批; draftEdit:草稿编辑;done:我的已办详情
      type: {
        type: String,
        default: "look"
      },
    },
    data() {
        let baseRules = {
            paperName: [
              { required: true, message: '必填项', trigger: 'blur' }
            ],
            keyword: [
              { required: true, message: '必填项', trigger: 'blur' }
            ],
            summary: [
              { required: true, message: '必填项', trigger: 'blur' }
            ],
            firstAuthor: [
              { required: true, message: '必填项', trigger: 'blur' }
            ],
            isPublish: [
              { required: true, message: '必填项', trigger: 'blur' }
            ],
          };
        let publishRules = {
            periodicalName: [
              { required: true, message: '必填项', trigger: 'blur' }
            ],
            periodicalCore: [
              { required: true, message: '必填项', trigger: 'blur' }
            ],
            publishDate: [
              { required: true, message: '必填项', trigger: 'blur' }
            ],
            indexType: [
              { required: true, message: '必填项', trigger: 'blur' }
            ],
        };
        return {
            isStartAct: true, // 是否新建
            fileListDislogVisible: false, //
            fileUploadUrl:process.env.UPDOWN_ROOT,
            showCollapse2:"1",
            showCollapse:"1",
            hasIcon:false,
            loading:false,
            fileList:[],
            fileListDownLoad:[],
            showCollapse1:"1",
            flowDetails:{
                nextActOptions:[],
                approvePerson:[],
                approvePersonId:[],
                activityName:'010',
                isEnd:false,
                actParticipants:{}
            },
            fileProps:[ //文件上传的属性
                {prop:'fileRealName',label:'文件名'},
                {prop:'createTime',label:'上传时间'},
            ],
            flow_access:{
                task_type:'',//任务类型
                mergeTask:'0',//合并任务
                slotCount:'1',//任务处理规则
                resign:'',//会签类型
                reselMan:'',//是否重选快速审批人
                act_name:'',//当前节点名称
                now_deal_act:'010',//当前节点
                deal_answer:'1',//同意 还是退回
                next_deal_act:'',//下一节点
                next_deal_name:[],//下一处理人 [pxmwrya]阮洋  多个
                deal_suggest:'',//审批意见
                copygive:[],//抄送人
                approveMan:'',//当前提交人 自己
                procInstId:'',//流程实例ID
                sn:'',//sn
                backAct:'',//退回节点  020
                backMan:'',//退回人
                procSetId:'',//流程集ID 兑奖流程 463
                fullName:'BMWS\\TestProcess',//流程全名
                procChName:'',//流程中文名
                procVerId:'',
                isEnd:false

            },
          paper:{
            // folio: '1',
             fileId: '',
            // deptId:'', //部门
            // deptName: '不知道什么部门',
            // contactUser:'',//联系人
            // mobile:'',//联系方式
            // year:'',//年度
            // purchaseContractItemList: [] //
            publishDate: null,
            processName:"",
            // operateType:"1",
          },
          rules:[{ required: true, message: '必填项',trigger: 'blur'}],
          professionalMap:[],//专业领域字典
          indexTypeMap: [],//索引类别字典
          deptIdMap: [],//专业分部字典

          baseRules,
          publishRules,
          paperRules: baseRules,
          paperFileList:[],

          nextObj: {},

          WFConfigActivityList:[],//储存全部节点信息
      }
     },
     computed: {
        ...mapState({
          tableHeaderBGC: state => state.common.tableHeaderBGC
        }),
        edit(){
          const { type } = this;
          return type == 'add' || type == 'edit' || type == 'draftEdit'
        }
    },
    watch: {
      "paper.isPublish":{
        handler:function(val){
          if(val == 1 ){
            this.paperRules = Object.assign({},this.baseRules,this.publishRules)
            // this.$refs.paper.clearValidate();
          }else{
            this.paperRules = this.baseRules;
          }
        }
      },

    },
    created () {
        //this.getNowUser();
          //this.dateFormat();
        },
    mounted() {

      //获取全部字典
      this.getAllMap();

      //数据初始化
      this.initData();


      //不是新增都需要显示详情
      if(this.type != "add" ){
        let id =""
        if(this.type == "approve" ){
           id = this.$router.history.current.query.obj.formInstID
        }else if(this.type == "draftEdit"){
          id = this.$router.history.current.query.obj.formno
        }else if(this.type == "done"){
          id = this.$router.history.current.query.obj.fromNO
        }else{
           id = this.$router.history.current.params.id
        }
        //获取详情
        this.getDetail(id)

      }
      if(this.type == "approve" ){
         this.isStartAct = false;
         this.nextObj = this.$router.history.current.query.obj || {};

         const {
           procInstID,
           showBack,
           backAct,
           backActName,
           backManName,
           backMan,
         } = this.nextObj;


        this.flowDetails = Object.assign({}, this.flowDetails, {
          showBack,
          backAct,
          backMan,
          backActName,
          backManName,
        })
         this.flow_access = Object.assign({}, this.flow_access, {
          procInstId:procInstID,
          backAct,
          backMan,
          backManName,
        })

      }


      if(this.type == "draftEdit"){
         this.nextObj = this.$router.history.current.query.obj || {};
         const {
           sourceactmetadata,
           targetactmetadata,
           startuser,
           startusercn,
           id,
         } = this.nextObj
         if(sourceactmetadata === "010"){
           this.isStartAct =true;
         }else{
           this.isStartAct =false;
         }
        this.flow_access.next_deal_act = targetactmetadata;
        let name = `[${startuser}]${startusercn}`;
        this.flow_access.next_deal_name.push(name);
        this.$set(this.flow_access,"draftId",id);
        this.$set(this.flow_access,"next_deal_id",this.nextObj.startuser.split(","));
      }

      if(this.type == "done"){
        this.nextObj = this.$router.history.current.query.obj || {};
        this.flow_access.act_name = this.nextObj.actName;
        this.flow_access.approveMan = `[${this.nextObj.startUser}]${this.nextObj.startCNUser}`;
      }


    },
    methods: {
        //获取全部字典
        getAllMap(){
          //专业领域字典
          this.sysDictLoadByPaging("achievement_professional",(result)=>{
              this.professionalMap = result.data
          })
          //索引类别字典
          this.sysDictLoadByPaging("achievement_index_type",(result)=>{
              this.indexTypeMap = result.data
          })
          //专业分部字典
          this.sysDictLoadByPaging("achievement_profession_dept",(result)=>{
              this.deptIdMap = result.data
          })

        },
        //获取字典接口
        sysDictLoadByPaging (key,callback) {
          sys_manage.sysDictLoadByPaging({dictGroupKey: key}, result => {
            if (result.code === Constant.RT_SUCCESS) {
              callback(result)
            } else {
              ALERT.error(result.msg)
            }
          })
        },
        uploadSuccess (res, fileKey) {
          if (res.data && res.data[0]) {
            this.paper.fileId = res.data[0].fileId
            let file = {name: res.data[0].fileName, url: res.data[0].url, id: res.data[0].fileId}
            this.paperFileList.push(file)
          }
        },
        uploadRemove (fileList, fileKey) {
          let resList = fileList.map(item => {
            return {
              name: item.name,
              url: item.url,
             id: item.fileId
            }
          })
          this.paperFileList = resList
          this.paper.fileId = resList.map(item=>item.id).join(",");
        },

        //获取详情
         getDetail(id){
          api_sri.sriGainPaperInfo({id}, result => {
            if (result.code === Constant.RT_SUCCESS) {
               this.paper = result.data
              //已有附件
              console.log("--596======this.paper===",this.paper)
              if(this.paper.fileId){
                this.paperFileList =[
                    {
                      name:this.paper.paperFileName,
                      id:this.paper.fileId,
                      url:this.paper.paperFilePath
                    }
                  ]
              }
            } else {
              ALERT.error(result.msg)
            }

          })

        },
        //数据初始化
        initData:function(){
            this.flow_access.procChName = store.state.proc.procName ? store.state.proc.procName : '论文提交流程';
            this.flow_access.fullName = 'SWP-SU\\sci_thesis';
            this.flow_access.procSetId = store.state.proc.procSetId;
            this.flow_access.procVerId = store.state.proc.procId;


            this.paper.processName = this.flow_access.procChName;
            //获取最新流程procId
            this.getWFConfigProc({fullName: this.flow_access.fullName});


        },
        getWFConfigProc(params){ // 获取最新流程procId
          let _this = this;
          getWFConfigProcID(params).then((result) => {
            if(result.status == "200" && result.data.code == "0"){
               let data = result.data.data || {}
               _this.flow_access.procSetId  = data.procSetID
              //  审批需要
               _this.flow_access.procId  = data.procID

              _this.getSomeInfo(data.procID);
            }else{
                _this.$alert(result.data.msg,_this.$t('cm.tips'));
            }
          }).catch((err) => {
              _this.$alert(err,_this.$t('cm.tips'));
          });
        },


        getSomeInfo(procVerId){
          let _this = this;
            //获取全部节点信息
           this.getWFConfigActivityHandle((result)=>{
                //储存全部节点信息
                _this.WFConfigActivityList = result.data.data.data;
                if(this.type=='approve'){
                    //获取流程的开始节点、下一节点还有下一节点处理人
                    let act_metadata_cur = null;
                    //匹配当前节点
                    let d = _this.WFConfigActivityList;//result.data.data.data;
                    for (let i = 0; i < d.length; i++) {
                        if (d[i].actName == _this.nextObj.activityName) {
                            act_metadata_cur = d[i].actMetaData
                        }
                    }
                    // if(this.nextObj.activityName == "010_提交论文"){
                    //     act_metadata_cur = "010";
                    // }else if(this.nextObj.activityName == "020_论文管理员审批") {
                    //     act_metadata_cur = "020";
                    // }

                    let data = {
                      act_id: this.nextObj.activityID,
                    //   act_metadata: this.nextObj.backAct[0], //这里不能这样判断，backAct不可能是当前环节的act_metadata
                      act_metadata: act_metadata_cur,
                      act_name: this.nextObj.activityName,
                      proc_id: this.nextObj.procID
                    }
                    _this.flow_access.act_name = data.act_name;//当前环节名称
                    _this.flowDetails.activityName = data.act_name;//用于页面显示
                    _this.flow_access.staffNoBefore=this.nextObj.preActivitySender; //上一审批人
                    _this.flow_access.procId = this.nextObj.procID;//提交需要
                    _this.flow_access.actId = this.nextObj.activityID;//提交需要
                    _this.flow_access.now_deal_act  = act_metadata_cur
                    //获取下一处理环节
                    _this.getNextDealNode(data);
                }else{
                    //获取流程的开始节点、下一节点还有下一节点处理人
                    let _this = this;
                    getStartAct(procVerId).then((result) => {
                        if(result.status == "200" && result.data.code == "0"){
                            let data = result.data.data.data;
                            _this.flow_access.act_name = data.act_name;//当前环节名称
                            _this.flowDetails.activityName = data.act_name;//用于页面显示
                            //获取下一处理环节
                            _this.getNextDealNode(data);
                        }else{
                            _this.$alert(result.data.msg,_this.$t('cm.tips'));
                        }
                    }).catch((err) => {
                        _this.$alert(err,_this.$t('cm.tips'));
                    });

                }
           })

        },

          // 保存草稿防抖
        saveDraftHandle:COMMON.debounce('saveProc',500,true),

       // 提交流程防抖
        saveProcHandle:COMMON.debounce('saveProc'),

        // 提交流程
        saveProc(isSaveDraft = false) {
            if(isSaveDraft || this.isStartAct){
               this.addProc(isSaveDraft);
            }else {
                this.purSubmitProcess();
            }
        },
        //添加一个流程
        addProc:function(isSaveDraft){
            //下一步处理人 设置
            if(document.getElementById("appMan")!= null && document.getElementById("appMan").value != ""){
                this.flow_access.next_deal_name = document.getElementById("appMan").value.split(',');
            }
            //判断是否为保存草稿
            if(isSaveDraft){
                this.flow_access.isSaveDraft = "1"; //说明是保存草稿
                this.flow_access.isModifyDraft = this.type === "draftEdit" ? "1" :"0" //编辑草稿
            }else {
                 this.flow_access.isSaveDraft = "0";
            }
            //判断获奖表
            this.$refs['paper'].validate((valid)=>{
                if(valid){
                    if (this.checkValid()) {
                        //设置任务类型、会签规则、会签类型、是否重选快速审批人 http://cudflow-d
                        let selNextAct = this.flowDetails.nextActOptions.find(n =>{
                            return (n.actMetadata == this.flow_access.next_deal_act);
                        })

                        this.flow_access.task_type = selNextAct.taskActType;
                        this.flow_access.mergeTask = selNextAct.isMergeTask;
                        this.flow_access.slotCount = selNextAct.taskProcessRule;
                        this.flow_access.resign = selNextAct.reSignType;
                        this.flow_access.reselMan = selNextAct.isReselFastDealer;

                        //设置关联文件
                        this.flow_access.fileList = this.fileListDownLoad;
                        console.log("--748--",this.fileListDownLoad);
                        // operateType 参数
                        if(this.type == "add"){
                          this.paper.operateType = "1"
                        }else{
                          this.paper.operateType = "2"
                        }

                        let _this = this;
                        this.flow_access.paper = this.paper;

                        api_sri.sriGainSavePaper(this.flow_access, result => {
                          if (result.code === Constant.RT_SUCCESS) {
                            ALERT.success(result.msg)
                          if(isSaveDraft){
                                _this.$router.push(Constant.ROUTE_MYDRAFT.index);
                            }else{
                                  _this.$router.push(Constant.ROUTE_ALREADY_DONE_TASK.index);
                            }
                          } else {
                            ALERT.success(result.msg)
                          }
                        })
                    }
                }else{
                    return false;
                }
            })
        },
        getNextDealNode:function(data){//获取下一节点 通过 下一步点处理人接口
            let _this = this;
            let procInstId = this.type=='approve' ? _this.nextObj.procInstID :0;
            let params = {
                actId: data.act_id,
                procInstId,
                procId: data.proc_id,
                node: data.act_metadata,
            }
            getNextApprovePerson(params).then((result) => {
                if(result.status == "200" && result.data.code == "0"){
                    let data = result.data.data.data;
                    this.getNextNodeInfo(data);
                }else{
                    _this.$alert(result.data.msg,_this.$t('cm.tips'));
                }
            }).catch((err) => {
                _this.$alert(err,_this.$t('cm.tips'));
            });
        },
        //获取全部节点信息
        getWFConfigActivityHandle(calback){
            let _this = this;
            let params = {
                fullName: this.flow_access.fullName,
                procSetId: "", //this.flow_access.procSetId
            };
            getWFConfigActivity(params).then((result) => {
                if (result.status == "200" && result.data.code == "0") {
                    calback(result)
                } else {
                    _this.$alert(result.data.msg, _this.$t('cm.tips'));
                }
            }).catch((err) => {
                _this.$alert(err, _this.$t('cm.tips'));
            });

        },
        //获取下一节点详情
        getNextNodeInfo: function (data) {
            //获取流程配置中的流程节点信息  可以存储在store中getBpmPscActInfo
            let _this = this;
            //存在多个下一环节的情况
            console.log('存在多个下一环节的情况', data)
            for (const metadata in data) {
                let d = _this.WFConfigActivityList;//result.data.data.data;
                for (let i = 0; i < d.length; i++) {
                    if (d[i].actMetaData == metadata) {
                        _this.flowDetails.actParticipants[metadata] = data[metadata];
                        _this.getNextNodeDetails(d[i]);
                    }
                }
            }
        },

        // 审批流程
        purSubmitProcess () {

           //抄送人
          if(document.getElementById("sendToMan")!= null && document.getElementById("sendToMan").value != ""){
              this.flow_access.copygive = document.getElementById("sendToMan").value.split(',');
          }

          if(this.flow_access.participantSelectRestlt) {
              let value = [];
              let parts = this.flow_access.participantSelectRestlt.split(",");
              for(let i = 0; i < parts.length; i++){
                  value.push(parts[i]);
              }
              this.flow_access.next_deal_name = value;
          }
          if(this.checkValid()){
              //设置任务类型、会签规则、会签类型、是否重选快速审批人 http://cudflow-d
              let selNextAct = this.flowDetails.nextActOptions.find(n =>{
                // return (n.actMetadata == this.flow_access.next_deal_act);
                return true;
              })

              // this.flow_access.act_name = selNextAct.actName;//当前环节名称
              // this.flow_access.actId = selNextAct.actId;//当前环节Id
              this.flow_access.act_name = this.nextObj.activityName;//当前环节名称
              this.flow_access.actId = this.nextObj.activityID;//当前环节Id
              this.flow_access.task_type = selNextAct.taskActType;
              this.flow_access.mergeTask = selNextAct.isMergeTask;
              this.flow_access.slotCount = selNextAct.taskProcessRule;
              this.flow_access.resign = selNextAct.reSignType;
              this.flow_access.reselMan = selNextAct.isReselFastDealer;
              this.flow_access.auditNote = this.flow_access.deal_suggest;
              this.flow_access.formInstID = this.nextObj.formInstID;
              this.flow_access.procInstId = this.nextObj.procInstID;
              this.flow_access.sn = this.nextObj.sn;
              //处理回退逻辑
              this.flow_access.backAct = this.nextObj.backAct[0];
              this.flow_access.backMan = this.nextObj.backMan[0];
              this.flow_access.backManName = this.nextObj.backManName[0];

              //设置关联文件
              this.flow_access.fileList = this.fileListDownLoad;
              console.log("--875--",this.fileListDownLoad);
              let _this = this;
              api_sri.sriGainPaperSubmitProcess(this.flow_access, result => {
                if (result.code === Constant.RT_SUCCESS) {
                  ALERT.success(result.msg)
                  _this.$router.push(Constant.ROUTE_ALREADY_DONE_TASK.index);
                } else {
                  ALERT.success(result.msg)
                }
              })
          }
        },
        //获取下一节点详细信息
        getNextNodeDetails(arr){
            let _this = this;
            getBpmPscActInfo({actId:arr.actID}).then((result) => {
                if(result.status == "200" && result.data.code == "0"){
                    let data = result.data.data.data;
                    //获取下一步点处理人
                    console.log('获取下一步点处理人', data)
                    _this.flowDetails.nextActOptions.push(data);
                }else{
                    _this.$alert(result.data.msg,_this.$t('cm.tips'));
                }
            }).catch((err) => {
                _this.$alert(err,_this.$t('cm.tips'));
            });

        },
        //统一用户格式
        unifyUser:function(users){
            for(let i = 0; i < users.length; i++){
                if(typeof(users[i].item_principal_desc) != "undefined" && typeof(users[i].item_principal_desc) != null){
                    this.flowDetails.approvePerson.push("["+users[i].item_principal+"]"+users[i].item_principal_desc);
                    this.flowDetails.approvePersonId.push(users[i].item_principal);
                }
            }
        },
        //上传文件时的回调
        upfileBack:function(response, file, fileList){
            this.loading = false;
            if(response.code == "0"){
                this.fileListDownLoad.push(response.data);
            }else{
                this.$alert(response.msg,this.$t('cm.tips'));
            }
        },
        //上传文件之前的处理
        beforeUpload:function(file){
            //在这里进行上传文件的设置
            let type = file.name.substring(file.name.lastIndexOf('.')+1);
            const limitSize = file.size / 1024 /1024 < 10; //文件大小限制
            if(!limitSize){
                this.$alert("上传文件大小不能超过10M",this.$t('cm.tips'));
            }
            return limitSize;
        },
        loadingFile:function(){
            this.loading = true;
        },
        uplofileError:function(){
            this.loading = false;
        },
        //删除文件
        delFiles:function(row){
            let _this = this;
            delFile({fileId:row.fileId}).then((result) => {
                if(result.status == "200" && result.data.code == "0"){
                    _this.fileListDownLoad.splice(_this.fileListDownLoad.findIndex(item => item.fileId===row.fileId),1);
                }else{
                    _this.$alert(result.data.msg,_this.$t('cm.tips'));
                }
            }).catch((err) => {
                _this.$alert(err,_this.$t('cm.tips'));
            });
        },
       checkValid() {
            if (!this.flow_access.deal_answer) {
                this.$alert("请选择处理结论!", this.$t('cm.tips'));
                return false;
            } else if (!this.flow_access.next_deal_act) {
                this.$alert("请选择下一环节!", this.$t('cm.tips'));
                return false;
            } else if (!this.flow_access.isEnd&&this.flow_access.deal_answer==1&&this.flow_access.next_deal_name.length == 0) {
                this.$alert("请选择下一步处理人", this.$t('cm.tips'));
                return false;
            } else {
                return true;
            }
        },
        addFileListDislog () {
          this.fileListDislogVisible = true
        },
        closeFileListDislog () {
          this.fileListDislogVisible = false
        },
        addFileList (data) {
          this.paper.purchaseContractItemList = data
          this.fileListDislogVisible = false
        }

    },
    filters:{

       dateFormat(data) {

                                  if (!COMMON.isNullOrUndefinedOrSpace(data)) {
                                        var date = new Date(data)
                                        var month =date.getMonth()+1;if(month<10){month="0"+month;}
                                        var day =date.getDate();if(day<10){day="0"+day;}
                                        var hours =date.getHours();if(hours<10){hours="0"+hours;}
                                        var min= date.getMinutes();if(min<10){ min="0"+min; }
                                        var sec= date.getSeconds();if(sec<10){sec="0"+sec;}
                                      return  date.getFullYear() + '-' + month + '-' + day
                                  }
                                      return data
                                }

    }


}
</script>

<style lang="scss">
    .thesis-detail{
      .el-form-item__content>span:empty:before{
        content:"--"
      }
    }

</style>
